package com.jsjosem.aftersales.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import java.util.ArrayList;
import java.util.List;

public class StateAdapter extends FragmentStateAdapter {

    private List<Fragment> fragments;

    public StateAdapter(FragmentActivity activity) {
        super(activity);
        if (fragments == null) {
            this.fragments = new ArrayList<>();
        }
    }

    public StateAdapter(FragmentActivity activity, List<Fragment> fragments) {
        super(activity);
        this.fragments = fragments;
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        return fragments.get(position);
    }

    @Override
    public int getItemCount() {
        return fragments.size();
    }

    public void addFragment(Fragment fragment) {
        fragments.add(fragment);
    }

    public void addAllFragment(List<Fragment> fragments) {
        this.fragments.addAll(fragments);
    }

    public void deleteFragment(Fragment fragment) {
        fragments.remove(fragment);
    }

    public void clearAllFragment() {
        fragments.clear();
    }

    public Fragment getFragment(int position) {
        return fragments.get(position);
    }

}
